package Lab05.Q4;

import static java.lang.Math.PI;

public abstract class Shape {
    protected double a;
    protected double b;

    public Shape() {
        this(0.0, 0.0);
    }

    public Shape(double a, double b) {
        if (a < 0) {
            this.a = 0.0;
            this.b = b;
        } else if (b < 0) {
            this.a = a;
            this.b = 0.0;
        } else {
            this.a = a;
            this.b = b;
        }
    }
    /**
     * set
    *@param a
    *@param b
    */
    public void set(double a, double b) {
        if (a < 0) {
            this.a = 0.0;
            this.b = b;
        } else if (b < 0) {
            this.a = a;
            this.b = 0.0;
        } else {
            this.a = a;
            this.b = b;
        }
    }

    /**
     * calcArea
     * 计算形状的面积
     *
     * @return 面积
     */
    abstract public double calcArea();//抽象方法  不能是private的

    /* 其他必要的方法，比如 getter 和 setter */
}

class Rectangle extends Shape {
    public Rectangle(double a, double b) {
        super(a, b);
    }

    @Override
    public double calcArea() {
        return this.a * this.b;
    }
}

class Rhombus extends Shape {
    public Rhombus(double a, double b) {
        super(a, b);
    }

    @Override
    public double calcArea() {
        return this.a * this.b / 2.0;
    }
}

class Ellipse extends Shape {
    public Ellipse(double a, double b) {
        super(a, b);
    }

    @Override
    public double calcArea() {
        return PI * this.a * this.b;
    }
}

